package com.viettel.pon.common;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class DialogCommon extends Activity{
	 private Activity _context;
	 
	    //Hàm dựng khởi tạo đối tượng
	    public DialogCommon(Activity context) {
	        this._context = context;
	    }
	    
	    public AlertDialog createDialogToLogin(String msg) {
			AlertDialog.Builder builder = new AlertDialog.Builder(_context);
		
			builder.setTitle("Thông báo");
		
			builder.setMessage(msg);
			builder.setCancelable(false);
			
			builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					
				}
			});
			AlertDialog dialog = builder.create();
			return dialog;
		}
		
	    public AlertDialog createDialogErrorNotReturn(String msg) {
			AlertDialog.Builder builder = new AlertDialog.Builder(_context);
			builder.setTitle("Thông báo");
			builder.setMessage(msg);
			builder.setCancelable(false);
		
			builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
				
				}
			});
			AlertDialog dialog = builder.create();
			return dialog;
		}
	    
	    public AlertDialog createDialogAndRunActivity(String title, String msg, final Class class1) {
			AlertDialog.Builder builder = new AlertDialog.Builder(_context);
			builder.setTitle(title);
			builder.setMessage(msg);
			builder.setCancelable(false);
		
			builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					Intent intent = new Intent();
					intent.setClass(_context, class1);
					intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					_context.startActivity(intent);
				}
			});
			
			builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
				  public void onClick(DialogInterface arg0, int arg1) {
					  // do something when the Cancel button is clicked
				  }});
			AlertDialog dialog = builder.create();
			return dialog;
		 }
		 
		 public AlertDialog createDialog(String title, String msg) {
				AlertDialog.Builder builder = new AlertDialog.Builder(_context);
				builder.setTitle(title);
				builder.setMessage(msg);
				builder.setCancelable(false);
			
				builder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						
					}
				});
				AlertDialog dialog = builder.create();
				return dialog;
		 }
	    
	 
	    public AlertDialog createDialogAndFocus(String title, String msg, final EditText editText) {
			AlertDialog.Builder builder = new AlertDialog.Builder(_context);
			builder.setTitle(title);
			builder.setMessage(msg);
			builder.setCancelable(false);
		
			builder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					editText.requestFocus();
				}
			});
			AlertDialog dialog = builder.create();
			return dialog;
		 }
		 
		 public AlertDialog createDialogAndFocus(String title, String msg, final Spinner spinner) {
				AlertDialog.Builder builder = new AlertDialog.Builder(_context);
				builder.setTitle(title);
				builder.setMessage(msg);
				builder.setCancelable(false);
			
				builder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						spinner.requestFocusFromTouch();
					}
				});
				AlertDialog dialog = builder.create();
				return dialog;
		 }
}
